home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume16 / pcomm2 / part04 < prev    next >
Encoding:
Internet Message Format  |  1988-09-14  |  50.8 KB

  1. Path: bbn.com!rsalz
  2. From: rsalz@uunet.uu.net (Rich Salz)
  3. Newsgroups: comp.sources.unix
  4. Subject: v16i009:  Modem communications package, Part04/08
  5. Message-ID: <1061@fig.bbn.com>
  6. Date: 13 Sep 88 16:42:42 GMT
  7. Lines: 2215
  8. Approved: rsalz@uunet.UU.NET
  9.  
  10. Submitted-by: Emmet P Gray <fthood!egray>
  11. Posting-number: Volume 16, Issue 9
  12. Archive-name: pcomm2/part04
  13.  
  14. #! /bin/sh
  15. # This is a shell archive, meaning:
  16. # 1. Remove everything above the #! /bin/sh line.
  17. # 2. Save the resulting text in a file.
  18. # 3. Execute the file with /bin/sh (not csh) to create:
  19. #    di_win.c
  20. #    dial.c
  21. #    expand.c
  22. #    getcwd.c
  23. #    getopt.c
  24. #    help.c
  25. #    info.c
  26. #    init.c
  27. #    input.c
  28. #    line_set.c
  29. #    list_dir.c
  30. #    ls_menu.c
  31. export PATH; PATH=/bin:/usr/bin:$PATH
  32. echo shar: "extracting 'di_win.c'" '(9165 characters)'
  33. if test -f 'di_win.c'
  34. then
  35.     echo shar: "will not over-write existing file 'di_win.c'"
  36. else
  37. sed 's/^X//' << \SHAR_EOF > 'di_win.c'
  38. X/*
  39. X * The dialing window routines.
  40. X */
  41. X
  42. X#define MAX_PASS 25
  43. X
  44. X#include <stdio.h>
  45. X#include <curses.h>
  46. X#include "config.h"
  47. X#include "dial_dir.h"
  48. X#include "misc.h"
  49. X#include "modem.h"
  50. X#include "param.h"
  51. X
  52. X/*
  53. X * The dialing window.  Its job is to kill the input routine, get a port,
  54. X * cycle thru the entries in the queue, while interpreting both the
  55. X * user's requests and the modem's responses.  A return code of 1 means
  56. X * we're ready to fire up the input routine.
  57. X */
  58. X
  59. Xint
  60. Xdial_win()
  61. X{
  62. X    extern int rc_index, fd;
  63. X    WINDOW *di_win, *newwin();
  64. X    int i, j, key, want_out, pass, tic, baud;
  65. X    long now, time();
  66. X    char *tbuf, *ctime(), *str, cr=13, *read_codes();
  67. X    void disp_queue(), send_str(), dial_it(), delay_times(), input_off();
  68. X    void error_win(), line_set(), hang_up(), zap_vs(), log_calls();
  69. X    void st_line();
  70. X    unsigned int sleep();
  71. X                    /* are we already talking? */
  72. X    input_off();
  73. X    hang_up(1);
  74. X
  75. X    touchwin(stdscr);
  76. X    refresh();
  77. X
  78. X    if (get_port())
  79. X        return(0);
  80. X    /*
  81. X     * If the phone number is a NULL, then either we are on a
  82. X     * direct line, or you want to do the dialing yourself.
  83. X     */
  84. X    if (*dir->number[dir->q_num[0]] == NULL) {
  85. X                    /* check LD permission */
  86. X        if (limit_ld(0))
  87. X            return(0);
  88. X                    /* can't talk directly to OBM */
  89. X        if (!strcmp(modem->mname[modem->m_cur], "OBM")) {
  90. X            error_win(0, "Can't access the On Board Modem directly",
  91. X             "You must use the automatic dialing feature");
  92. X            return(0);
  93. X        }
  94. X
  95. X        zap_vs();
  96. X        touchwin(stdscr);
  97. X        clear();
  98. X        printw("Connected to /dev/%s at %d baud...\n", modem->tty[modem->t_cur], dir->baud[dir->d_cur]);
  99. X        refresh();
  100. X        return(1);
  101. X    }
  102. X
  103. X    di_win = newwin(17, 70, 3, 5);
  104. X                    /* the basic window */
  105. X    mvwattrstr(di_win, 1, 20, A_BOLD, "D I A L I N G       W I N D O W");
  106. X    horizontal(di_win, 2, 0, 70);
  107. X    mvwaddstr(di_win, 4, 23, "System name:");
  108. X    mvwaddstr(di_win, 5, 23, "Pass number:");
  109. X    mvwaddstr(di_win, 6, 14, "Elapse time this try:");
  110. X    mvwaddstr(di_win, 7, 13, "Time at start of dial:");
  111. X    mvwaddstr(di_win, 8, 9, "Time at start of this try:");
  112. X    mvwaddstr(di_win, 9, 16, "Connect delay time:");
  113. X    mvwaddstr(di_win, 10, 17, "Redial delay time:");
  114. X    mvwaddstr(di_win, 11, 25, "Index/TTY:");
  115. X    mvwaddstr(di_win, 12, 16, "Result of last try:");
  116. X
  117. X    mvwaddstr(di_win, 14, 3, "<SPACE>: Recycle");
  118. X    mvwaddstr(di_win, 14, 22, "<DEL>: Remove from queue");
  119. X    mvwaddstr(di_win, 14, 49, "E: Change delays");
  120. X
  121. X                    /* the start time */
  122. X    time(&now);
  123. X    tbuf = ctime(&now);
  124. X    tbuf[19] = NULL;
  125. X    mvwaddstr(di_win, 7, 36, &tbuf[11]);
  126. X
  127. X    mvwprintw(di_win, 9, 36, "%-4d", param->c_delay);
  128. X    mvwprintw(di_win, 10, 36, "%-4d", param->r_delay);
  129. X
  130. X    box(di_win, VERT, HORZ);
  131. X    mvwaddstr(di_win, 16, 24, " Press <ESC> to abort ");
  132. X
  133. X    pass = 0;
  134. X    i = 0;
  135. X    want_out = 0;
  136. X    while (!want_out && pass <= MAX_PASS) {
  137. X        key = -1;
  138. X        pass++;
  139. X                    /* update the d_cur variable */
  140. X        dir->d_cur = dir->q_num[i];
  141. X                    /* check LD permission */
  142. X        if (limit_ld(i)) {
  143. X            want_out++;
  144. X            break;
  145. X        }
  146. X                    /* get a port */
  147. X        if (get_port()) {
  148. X            want_out++;
  149. X            break;
  150. X        }
  151. X                    /* fill in the window */
  152. X        disp_queue(di_win, dir->d_cur, pass);
  153. X
  154. X        /*
  155. X         * The actual dial routine.  The "i" is the index into the
  156. X         * queue, not the entry number.  Returns immediately without
  157. X         * waiting for a carrier.
  158. X         */
  159. X        dial_it(i);
  160. X        ioctl(fd, TCFLSH, 0);
  161. X
  162. X        /*
  163. X         * Here we do a time-slice between reading the result codes
  164. X         * from the modem and reading the keyboard.  The one second
  165. X         * granularity won't be too accurate, but who cares?
  166. X         */
  167. X        tic = 0;
  168. X        rc_index = 0;
  169. X        while (tic < param->c_delay) {
  170. X            if ((str = read_codes()) == NULL) {
  171. X                mvwprintw(di_win, 6, 36, "%-4d", ++tic);
  172. X                wrefresh(di_win);
  173. X            }
  174. X            else {
  175. X                /*
  176. X                 * A return code that converts to an number
  177. X                 * that is less than 300 is probably an error
  178. X                 * message.
  179. X                 */
  180. X                baud = atoi(str);
  181. X                if (baud < 300) {
  182. X                    mvwprintw(di_win, 12, 36, "%-20.20s", str);
  183. X                    wmove(di_win, 12, 36);
  184. X                    wrefresh(di_win);
  185. X                    break;
  186. X                }
  187. X                    /* we're connected */
  188. X                beep();
  189. X                clear_line(di_win, 12, 36, 1);
  190. X                wattrstr(di_win, A_BLINK, "CONNECTED");
  191. X                wmove(di_win, 12, 36);
  192. X                wrefresh(di_win);
  193. X                wait_key(di_win, 2);
  194. X                delwin(di_win);
  195. X
  196. X                /*
  197. X                 * Did the modem sync at a different baud
  198. X                 * rate than what we expected?
  199. X                 */
  200. X                if (dir->baud[dir->d_cur] != baud) {
  201. X                    if (can_sync(baud)) {
  202. X                        dir->baud[dir->d_cur] = baud;
  203. X                        line_set();
  204. X                    }
  205. X                }
  206. X
  207. X                zap_vs();
  208. X                touchwin(stdscr);
  209. X                clear();
  210. X                printw("Connected to %s at %d baud...\n",
  211. X                 dir->name[dir->d_cur], dir->baud[dir->d_cur]);
  212. X                refresh();
  213. X
  214. X                    /* log the call */
  215. X                log_calls(i);
  216. X                return(1);
  217. X            }
  218. X            if (tic == param->c_delay)
  219. X                break;
  220. X                    /* ok... try the keyboard */
  221. X            if ((key = wait_key(di_win, 1)) != -1)
  222. X                break;
  223. X
  224. X            mvwprintw(di_win, 6, 36, "%-4d", ++tic);
  225. X            wrefresh(di_win);
  226. X        }
  227. X        /*
  228. X         * If the modem did not return a code, then we need to
  229. X         * stop it.  Sending a CR will stop most modems cold,
  230. X         * except of course for the OBM...
  231. X         */
  232. X        if (str == NULL) {
  233. X            if (!strcmp(modem->mname[modem->m_cur], "OBM"))
  234. X                hang_up(0);
  235. X            else
  236. X                write(fd, &cr, 1);
  237. X            sleep(1);
  238. X        }
  239. X                    /* if we get here, no key was pressed */
  240. X        if (key == -1) {
  241. X            clear_line(di_win, 6, 14, 1);
  242. X            mvwaddstr(di_win, 6, 27, "Pausing:");
  243. X                    /* no return code? */
  244. X            if (str == NULL) {
  245. X                clear_line(di_win, 12, 36, 1);
  246. X                waddstr(di_win, "TIMED OUT");
  247. X                wmove(di_win, 12, 36);
  248. X            }
  249. X                    /* do the pause */
  250. X            tic = 0;
  251. X            while (tic < param->r_delay) {
  252. X                if ((key = wait_key(di_win, 1)) != -1)
  253. X                    break;
  254. X                mvwprintw(di_win, 6, 36, "%-4d", ++tic);
  255. X                wrefresh(di_win);
  256. X            }
  257. X            clear_line(di_win, 6, 14, 1);
  258. X            waddstr(di_win, "Elapse time this try:");
  259. X        }
  260. X        mvwaddstr(di_win, 6, 36, "0   ");
  261. X                    /* Process the keystroke */
  262. X        switch (key) {
  263. X            case ' ':    /* next in the queue */
  264. X                clear_line(di_win, 12, 36, 1);
  265. X                waddstr(di_win, "RECYCLED");
  266. X                wmove(di_win, 12, 36);
  267. X                wrefresh(di_win);
  268. X                /* fall thru... */
  269. X            case -1:    /* no key was pressed */
  270. X                i++;
  271. X                if (i > NUM_QUEUE)
  272. X                    i = 0;
  273. X                if (dir->q_num[i] == -1)
  274. X                    i = 0;
  275. X                break;
  276. X            case DEL:    /* <DEL> key, remove from queue */
  277. X                if (dir->q_num[1] == -1) {
  278. X                    beep();
  279. X                    clear_line(di_win, 12, 36, 1);
  280. X                    waddstr(di_win, "NO MORE ENTRIES");
  281. X                    wmove(di_win, 12, 36);
  282. X                    wrefresh(di_win);
  283. X                    wait_key(di_win, 3);
  284. X                    break;
  285. X                }
  286. X                clear_line(di_win, 12, 36, 1);
  287. X                waddstr(di_win, "ENTRY DELETED");
  288. X                wmove(di_win, 12, 36);
  289. X                wrefresh(di_win);
  290. X                wait_key(di_win, 3);
  291. X
  292. X                    /* compact the queue */
  293. X                for (j=i; j<NUM_QUEUE-1; j++)
  294. X                    dir->q_num[j] = dir->q_num[j+1];
  295. X                dir->q_num[NUM_QUEUE-1] = -1;
  296. X                break;
  297. X            case 'e':
  298. X            case 'E':    /* change delay time */
  299. X                delay_times();
  300. X                touchwin(di_win);
  301. X                mvwprintw(di_win, 9, 36, "%-4d", param->c_delay);
  302. X                mvwprintw(di_win, 10, 36, "%-4d", param->r_delay);
  303. X                break;
  304. X            case ESC:    /* <ESC> key */
  305. X                beep();
  306. X                clear_line(di_win, 12, 36, 1);
  307. X                wattrstr(di_win, A_BLINK, "DIAL ABORTED");
  308. X                wmove(di_win, 12, 36);
  309. X                wrefresh(di_win);
  310. X                wait_key(di_win, 3);
  311. X                want_out++;
  312. X                break;
  313. X            default:
  314. X                beep();
  315. X                break;
  316. X        }
  317. X    }
  318. X                    /* clean up and go home */
  319. X    werase(di_win);
  320. X    wrefresh(di_win);
  321. X    delwin(di_win);
  322. X    if (!want_out)
  323. X        error_win(0, "Exceeded the maximum number number of dialing attempts", "");
  324. X    return(0);
  325. X}
  326. X
  327. X/*
  328. X * Display what info we know at this time.
  329. X */
  330. X
  331. Xstatic void
  332. Xdisp_queue(win, entry, pass)
  333. XWINDOW *win;
  334. Xint entry, pass;
  335. X{
  336. X    long now, time();
  337. X    char *tbuf, *ctime();
  338. X    void st_line();
  339. X                    /* redo the status line */
  340. X    st_line("");
  341. X                    /* system name */
  342. X    clear_line(win, 4, 36, 1);
  343. X    waddstr(win, dir->name[entry]);
  344. X                    /* pass number */
  345. X    mvwprintw(win, 5, 36, "%-4d", pass);
  346. X                    /* time of this call */
  347. X    time(&now);
  348. X    tbuf = ctime(&now);
  349. X    tbuf[19] = NULL;
  350. X    mvwaddstr(win, 8, 36, &tbuf[11]);
  351. X                    /* the index field */
  352. X    clear_line(win, 11, 36, 1);
  353. X    waddstr(win, dir->index[entry]);
  354. X
  355. X    wmove(win, 12, 36);
  356. X    wrefresh(win);
  357. X    return;
  358. X}
  359. X
  360. X/*
  361. X * Determine if the modem can detect the synchronization of the connected
  362. X * baud rate.  We check the modem database and see if the connect string
  363. X * is unique.  A return code of 1 means the modem can sync.
  364. X */
  365. X
  366. Xstatic int
  367. Xcan_sync(baud)
  368. Xint baud;
  369. X{
  370. X    int i;
  371. X    char *str;
  372. X                    /* feature disabled? */
  373. X    if (modem->auto_baud[modem->m_cur] != 'Y')
  374. X        return(0);
  375. X                    /* re-construct the string */
  376. X    switch (baud) {
  377. X        case 300:
  378. X            str = modem->con_3[modem->m_cur];
  379. X            break;
  380. X        case 1200:
  381. X            str = modem->con_12[modem->m_cur];
  382. X            break;
  383. X        case 2400:
  384. X            str = modem->con_24[modem->m_cur];
  385. X            break;
  386. X        case 4800:
  387. X            str = modem->con_48[modem->m_cur];
  388. X            break;
  389. X        case 9600:
  390. X            str = modem->con_96[modem->m_cur];
  391. X            break;
  392. X        case 19200:
  393. X            str = modem->con_192[modem->m_cur];
  394. X            break;
  395. X        default:
  396. X            return(0);
  397. X    }
  398. X
  399. X    if (*str == NULL)
  400. X        return(0);
  401. X                    /* test "str" against all others */
  402. X    i = 0;
  403. X    if (!strcmp(str, modem->con_3[modem->m_cur]))
  404. X        i++;
  405. X    if (!strcmp(str, modem->con_12[modem->m_cur]))
  406. X        i++;
  407. X    if (!strcmp(str, modem->con_24[modem->m_cur]))
  408. X        i++;
  409. X    if (!strcmp(str, modem->con_48[modem->m_cur]))
  410. X        i++;
  411. X    if (!strcmp(str, modem->con_96[modem->m_cur]))
  412. X        i++;
  413. X    if (!strcmp(str, modem->con_192[modem->m_cur]))
  414. X        i++;
  415. X                    /* should match only itself */
  416. X    if (i == 1)
  417. X        return(1);
  418. X    return(0);
  419. X}
  420. SHAR_EOF
  421. if test 9165 -ne "`wc -c < 'di_win.c'`"
  422. then
  423.     echo shar: "error transmitting 'di_win.c'" '(should have been 9165 characters)'
  424. fi
  425. fi
  426. echo shar: "extracting 'dial.c'" '(7336 characters)'
  427. if test -f 'dial.c'
  428. then
  429.     echo shar: "will not over-write existing file 'dial.c'"
  430. else
  431. sed 's/^X//' << \SHAR_EOF > 'dial.c'
  432. X/*
  433. X * The routines that dial the modem and listen for the return codes.
  434. X */
  435. X
  436. X#include <stdio.h>
  437. X#include <termio.h>
  438. X#include "config.h"
  439. X#ifdef UNIXPC
  440. X#include <sys/phone.h>
  441. X#endif /* UNIXPC */
  442. X#include "dial_dir.h"
  443. X#include "misc.h"
  444. X#include "modem.h"
  445. X#include "param.h"
  446. X
  447. X/*
  448. X * Get the dial string ready, send it to the modem.  The parameter is not
  449. X * the actual entry number, it is an index into the queue.
  450. X */
  451. X
  452. Xvoid
  453. Xdial_it(num)
  454. Xint num;
  455. X{
  456. X    extern int fd;
  457. X    int i, skip;
  458. X    char s[100], number[40], *strcpy(), *strcat(), *n, *strchr();
  459. X    void send_str();
  460. X#ifdef UNIXPC
  461. X    struct updata pbuf;
  462. X    unsigned int sleep();
  463. X#endif /* UNIXPC */
  464. X
  465. X    /*
  466. X     * Create the string to be sent to the modem.  The long distance
  467. X     * codes are added if they are requested.
  468. X     */
  469. X    s[0] = NULL;
  470. X    strcpy(s, modem->dial[modem->m_cur]);
  471. X
  472. X    switch (dir->q_ld[num]) {
  473. X        case 0:            /* no ld code requested */
  474. X            break;
  475. X        case '+':
  476. X            strcat(s, param->ld_plus);
  477. X            break;
  478. X        case '-':
  479. X            strcat(s, param->ld_minus);
  480. X            break;
  481. X        case '@':
  482. X            strcat(s, param->ld_at);
  483. X            break;
  484. X        case '#':
  485. X            strcat(s, param->ld_pound);
  486. X            break;
  487. X    }
  488. X    /*
  489. X     * Purify the phone number by removing all the pretty characters
  490. X     * that don't need to be sent to the modem.  Typically the "-",
  491. X     * "(", ")", and space characters are just for looks.  To prevent
  492. X     * this action, prepend a "\" to the character.
  493. X     */
  494. X    i = 0;
  495. X    skip = 0;
  496. X    n = dir->number[dir->q_num[num]];
  497. X    while (*n) {
  498. X        if (*n == '\\' && !skip) {
  499. X            skip++;
  500. X            n++;
  501. X            continue;
  502. X        }
  503. X        if (!strchr("-() ", *n) || skip)
  504. X            number[i++] = *n;
  505. X        n++;
  506. X        skip = 0;
  507. X    }
  508. X    number[i] = NULL;
  509. X                    /* add it to the string */
  510. X    strcat(s, number);
  511. X    strcat(s, modem->suffix[modem->m_cur]);
  512. X#ifdef DEBUG
  513. X    fprintf(stderr, "raw dial string: '%s'\n", s);
  514. X#endif /* DEBUG */
  515. X
  516. X#ifdef UNIXPC
  517. X                    /* special case for OBM */
  518. X    if (!strcmp(modem->mname[modem->m_cur], "OBM")) {
  519. X                    /* prepare the modem */
  520. X        pbuf.c_lineparam = DATA|DTMF;
  521. X        pbuf.c_waitdialtone = 5;
  522. X        pbuf.c_linestatus = 0;
  523. X        pbuf.c_feedback = SPEAKERON|NORMSPK;
  524. X        pbuf.c_waitflash = 500;
  525. X        ioctl(fd, PIOCSETP, &pbuf);
  526. X        sleep(1);
  527. X                    /* connect the dialer */
  528. X        ioctl(fd, PIOCRECONN);
  529. X        sleep(1);
  530. X                    /* dial each digit */
  531. X        n = s;
  532. X        while (*n) {
  533. X                    /* switch tone/pulse dialing? */
  534. X            switch (*n) {
  535. X                case '^':
  536. X                    pbuf.c_lineparam = DATA|PULSE;
  537. X                    ioctl(fd, PIOCSETP, &pbuf);
  538. X                    break;
  539. X                case '%':
  540. X                    pbuf.c_lineparam = DATA|DTMF;
  541. X                    ioctl(fd, PIOCSETP, &pbuf);
  542. X                    break;
  543. X                default:
  544. X                    ioctl(fd, PIOCDIAL, n);
  545. X                    break;
  546. X            }
  547. X            n++;
  548. X        }
  549. X        return;
  550. X    }
  551. X#endif /* UNIXPC */
  552. X
  553. X    send_str(s);
  554. X    return;
  555. X}
  556. X
  557. X/*
  558. X * Send a string to the modem.  Performs all the character synonym
  559. X * translations.  No sanity checking on the "m_cur" value.
  560. X */
  561. X
  562. Xvoid
  563. Xsend_str(s)
  564. Xchar *s;
  565. X{
  566. X    extern int fd;
  567. X    int skip;
  568. X    unsigned int sleep();
  569. X                    /* empty string? */
  570. X    if (s == NULL || *s == NULL)
  571. X        return;
  572. X
  573. X    ioctl(fd, TCFLSH, 1);
  574. X    /*
  575. X     * Change the character synonyms to their real values.  Writes
  576. X     * the characters to the modem.  To remove the special meaning
  577. X     * of one of the characters, prepend a "\" to it.
  578. X     */
  579. X    skip = 0;
  580. X    while (*s) {
  581. X                    /* send the literal character */
  582. X        if (skip) {
  583. X            skip = 0;
  584. X            write(fd, s, 1);
  585. X            ioctl(fd, TCSBRK, 1);
  586. X#ifdef DEBUG
  587. X            fprintf(stderr, "send_str: '%c', %02x, %03o, %d\n", *s, *s, *s, *s);
  588. X#endif /* DEBUG */
  589. X            s++;
  590. X            continue;
  591. X        }
  592. X                    /* turn off the special meaning */
  593. X        if (*s == '\\') {
  594. X            skip++;
  595. X            s++;
  596. X            continue;
  597. X        }
  598. X                    /* pause synonym */
  599. X        if (*s == param->pause_char) {
  600. X            sleep(1);
  601. X            s++;
  602. X            continue;
  603. X        }
  604. X                    /* carriage return synonym */
  605. X        if (*s == param->cr_char)
  606. X            *s = '\r';
  607. X                    /* 2 character control sequence */
  608. X        if (*s == param->ctrl_char) {
  609. X            s++;
  610. X                    /* premature EOF? */
  611. X            if (*s == NULL)
  612. X                break;
  613. X                    /* upper and lower case */
  614. X            if (*s > '_')
  615. X                *s -= 96;
  616. X            else
  617. X                *s -= 64;
  618. X        }
  619. X                    /* escape synonym */
  620. X        if (*s == param->esc_char)
  621. X            *s = ESC;
  622. X                    /* modem break synonym */
  623. X        if (*s == param->brk_char) {
  624. X            ioctl(fd, TCSBRK, 0);
  625. X            sleep(1);
  626. X            s++;
  627. X            continue;
  628. X        }
  629. X
  630. X        write(fd, s, 1);
  631. X#ifdef DEBUG
  632. X        fprintf(stderr, "send_str: '%c', %02x, %03o, %d\n", *s, *s, *s, *s);
  633. X#endif /* DEBUG */
  634. X        /*
  635. X         * Because the pause char makes the timing critical, we
  636. X         * wait until the buffer is clear before we continue.
  637. X         */
  638. X        ioctl(fd, TCSBRK, 1);
  639. X        s++;
  640. X    }
  641. X    return;
  642. X}
  643. X
  644. X/*
  645. X * Read the result codes coming back from the modem.  Test for the 6
  646. X * "connect" strings and the 4 "no connect" strings.  Return the connected
  647. X * baud rate (as a string) or the error message.
  648. X */
  649. X
  650. Xchar rc_buf[512];
  651. Xint rc_index;
  652. X
  653. Xchar *
  654. Xread_codes()
  655. X{
  656. X    extern int fd;
  657. X    char c;
  658. X#ifdef UNIXPC
  659. X    unsigned int sleep();
  660. X    struct updata pbuf;
  661. X                    /* special case for OBM */
  662. X    if (!strcmp(modem->mname[modem->m_cur], "OBM")) {
  663. X        ioctl(fd, PIOCGETP, &pbuf);
  664. X
  665. X        /*
  666. X         * The OBM doesn't use a return message to announce the
  667. X         * connection to a remote, so we fake one.  The 1200
  668. X         * is quite arbitrary... it is not an indicator of the
  669. X         * connected baud rate.
  670. X         */
  671. X        if (pbuf.c_linestatus & MODEMCONNECTED)
  672. X            return("1200");
  673. X
  674. X        sleep(1);
  675. X        return(NULL);
  676. X    }
  677. X#endif /* UNIXPC */
  678. X                    /* search for key words */
  679. X    for (; rc_index<511; rc_index++) {
  680. X        if ((int) (c = getc_line(1)) <= 0)
  681. X            return(NULL);
  682. X#ifdef DEBUG
  683. X        fprintf(stderr, "read_codes: '%c', %02x, %03o, %d\n", c, c, c, c);
  684. X#endif /* DEBUG */
  685. X
  686. X        rc_buf[rc_index] = c;
  687. X        rc_buf[rc_index+1] = NULL;
  688. X                    /* the connect strings */
  689. X        if (match(rc_buf, modem->con_3[modem->m_cur]))
  690. X            return("300");
  691. X
  692. X        if (match(rc_buf, modem->con_12[modem->m_cur]))
  693. X            return("1200");
  694. X
  695. X        if (match(rc_buf, modem->con_24[modem->m_cur]))
  696. X            return("2400");
  697. X
  698. X        if (match(rc_buf, modem->con_48[modem->m_cur]))
  699. X            return("4800");
  700. X
  701. X        if (match(rc_buf, modem->con_96[modem->m_cur]))
  702. X            return("9600");
  703. X
  704. X        if (match(rc_buf, modem->con_192[modem->m_cur]))
  705. X            return("19200");
  706. X
  707. X                    /* the no connect strings */
  708. X        if (match(rc_buf, modem->no_con1[modem->m_cur]))
  709. X            return(modem->no_con1[modem->m_cur]);
  710. X
  711. X        if (match(rc_buf, modem->no_con2[modem->m_cur]))
  712. X            return(modem->no_con2[modem->m_cur]);
  713. X
  714. X        if (match(rc_buf, modem->no_con3[modem->m_cur]))
  715. X            return(modem->no_con3[modem->m_cur]);
  716. X
  717. X        if (match(rc_buf, modem->no_con4[modem->m_cur]))
  718. X            return(modem->no_con4[modem->m_cur]);
  719. X    }
  720. X                    /* ran out of buffer? */
  721. X    return("ERROR");
  722. X}
  723. X
  724. X/*
  725. X * Test for a match between two character strings.  A return code of 1
  726. X * means that s2 was found at the end of s1.
  727. X */
  728. X
  729. Xstatic int
  730. Xmatch(s1, s2)
  731. Xchar *s1, *s2;
  732. X{
  733. X    register int i;
  734. X    int skip, diff;
  735. X    char new[40];
  736. X                    /* if no string to match */
  737. X    if (*s2 == NULL)
  738. X        return(0);
  739. X                    /* translate synonyms */
  740. X    i = 0;
  741. X    skip = 0;
  742. X    while (*s2) {
  743. X                    /* literal character */
  744. X        if (skip) {
  745. X            skip = 0;
  746. X            new[i++] = *s2;
  747. X            s2++;
  748. X            continue;
  749. X        }
  750. X                    /* turn off the special meaning */
  751. X        if (*s2 == '\\') {
  752. X            skip++;
  753. X            s2++;
  754. X            continue;
  755. X        }
  756. X                    /* carriage return synonym */
  757. X        if (*s2 == param->cr_char)
  758. X            *s2 = '\r';
  759. X
  760. X                    /* 2 character control sequence */
  761. X        if (*s2 == param->ctrl_char) {
  762. X            s2++;
  763. X            if (*s2 == NULL)
  764. X                break;
  765. X            if (*s2 > '_')
  766. X                *s2 -= 96;
  767. X            else
  768. X                *s2 -= 64;
  769. X        }
  770. X                    /* escape synonym */
  771. X        if (*s2 == param->esc_char)
  772. X            *s2 = ESC;
  773. X
  774. X        new[i++] = *s2;
  775. X        s2++;
  776. X    }
  777. X    new[i] = NULL;
  778. X
  779. X    diff = strlen(s1) - strlen(new);
  780. X                    /* is it possible? */
  781. X    if (diff < 0)
  782. X        return(0);
  783. X                    /* test it out */
  784. X    if (!strcmp(&s1[diff], new))
  785. X        return(1);
  786. X    return(0);
  787. X}
  788. SHAR_EOF
  789. if test 7336 -ne "`wc -c < 'dial.c'`"
  790. then
  791.     echo shar: "error transmitting 'dial.c'" '(should have been 7336 characters)'
  792. fi
  793. fi
  794. echo shar: "extracting 'expand.c'" '(2683 characters)'
  795. if test -f 'expand.c'
  796. then
  797.     echo shar: "will not over-write existing file 'expand.c'"
  798. else
  799. sed 's/^X//' << \SHAR_EOF > 'expand.c'
  800. X/*
  801. X * Do file name expansion with "native" shell.  Using the native shell
  802. X * (as described in the SHELL environmental variable) allows for csh or
  803. X * ksh abbreviations that sh doesn't recognize.
  804. X */
  805. X
  806. X#include <stdio.h>
  807. X#include <signal.h>
  808. X#include <fcntl.h>
  809. X#include "config.h"
  810. X
  811. Xchar *
  812. Xexpand(input)
  813. Xchar *input;
  814. X{
  815. X    extern char *null_ptr;
  816. X    FILE *pfp, *n_popen();
  817. X    int last;
  818. X    char *ans, buf[1024], *strpbrk(), *strdup();
  819. X    void free_ptr();
  820. X
  821. X                    /* same rules as strdup() */
  822. X    if (input == NULL)
  823. X        return(NULL);
  824. X    if (*input == NULL)
  825. X        return(null_ptr);
  826. X                    /* any thing to expand? */
  827. X    ans = strdup(input);
  828. X    if (!strpbrk(input, "$*{}[]\\?~"))
  829. X        return(ans);
  830. X                    /* popen an echo */
  831. X    sprintf(buf, "echo %s", input);
  832. X
  833. X    pfp = n_popen(buf, "r");
  834. X    fgets(buf, 1024, pfp);
  835. X    n_pclose(pfp);
  836. X
  837. X    if (!strlen(buf))
  838. X        return(ans);
  839. X    /*
  840. X     * A horrible kludge...  if the last character is not a line
  841. X     * feed, then the csh has returned an error message.  Otherwise
  842. X     * zap the line feed.
  843. X     */
  844. X    last = strlen(buf) -1;
  845. X    if (buf[last] != '\n')
  846. X        return(ans);
  847. X    else
  848. X        buf[last] = NULL;
  849. X
  850. X    free_ptr(ans);
  851. X    ans = strdup(buf);
  852. X    return(ans);
  853. X}
  854. X
  855. X#define    tst(a,b) (*mode == 'r'? (b) : (a))
  856. X#define    RDR    0
  857. X#define    WTR    1
  858. Xstatic int popen_pid[20];
  859. X
  860. XFILE *
  861. Xn_popen(cmd, mode)
  862. Xchar *cmd, *mode;
  863. X{
  864. X    int myside, hisside, ppid, p[2];
  865. X    char *shellpath, *shell, *flags, *getenv(), *strrchr();
  866. X    void _exit();
  867. X
  868. X    if (pipe(p) < 0)
  869. X        return NULL;
  870. X
  871. X    myside = tst(p[WTR], p[RDR]);
  872. X    hisside = tst(p[RDR], p[WTR]);
  873. X                    /* get the environmental variable */
  874. X    shellpath = getenv("SHELL");
  875. X    if (shellpath == NULL || *shellpath == NULL)
  876. X        shellpath = "/bin/sh";
  877. X
  878. X    shell = strrchr(shellpath, '/') + 1;
  879. X                    /* fix up the flags */
  880. X    if (!strcmp(shell, "csh"))
  881. X        flags = "-fc";
  882. X    else
  883. X        flags = "-c";        /* Korn shell too */
  884. X
  885. X    if (!(ppid = fork())) {
  886. X        int stdio;
  887. X                    /* no error messages please */
  888. X        close(2);
  889. X        open("/dev/null", O_WRONLY);
  890. X#ifdef SETUGID
  891. X        setgid(getgid());
  892. X        setuid(getuid());
  893. X#endif /* SETUGID */
  894. X        stdio = tst(0, 1);
  895. X        close(myside);
  896. X        close(stdio);
  897. X        fcntl(hisside, F_DUPFD, stdio);
  898. X        close(hisside);
  899. X        execl(shellpath, shell, flags, cmd, (char *) 0);
  900. X        _exit(1);
  901. X    }
  902. X    if (ppid == -1) {
  903. X        close(myside);
  904. X        close(hisside);
  905. X        return NULL;
  906. X    }
  907. X
  908. X    popen_pid[myside] = ppid;
  909. X
  910. X    close(hisside);
  911. X    return(fdopen(myside, mode));
  912. X}
  913. X
  914. Xn_pclose(ptr)
  915. XFILE *ptr;
  916. X{
  917. X    int f, r, (*hstat)(), (*istat)(), (*qstat)(), status;
  918. X
  919. X    f = fileno(ptr);
  920. X    fclose(ptr);
  921. X    istat = signal(SIGINT, SIG_IGN);
  922. X    qstat = signal(SIGQUIT, SIG_IGN);
  923. X    hstat = signal(SIGHUP, SIG_IGN);
  924. X
  925. X    while ((r = wait(&status)) != popen_pid[f] && r != -1)
  926. X        ;
  927. X
  928. X    if (r == -1)
  929. X        status = -1;
  930. X
  931. X    signal(SIGINT, istat);
  932. X    signal(SIGQUIT, qstat);
  933. X    signal(SIGHUP, hstat);
  934. X    return(status);
  935. X}
  936. SHAR_EOF
  937. if test 2683 -ne "`wc -c < 'expand.c'`"
  938. then
  939.     echo shar: "error transmitting 'expand.c'" '(should have been 2683 characters)'
  940. fi
  941. fi
  942. echo shar: "extracting 'getcwd.c'" '(387 characters)'
  943. if test -f 'getcwd.c'
  944. then
  945.     echo shar: "will not over-write existing file 'getcwd.c'"
  946. else
  947. sed 's/^X//' << \SHAR_EOF > 'getcwd.c'
  948. X/*
  949. X * Can you believe it???  Masscomps don't have a function to return the
  950. X * current working directory while in the AT&T universe!
  951. X */
  952. X
  953. X#include <stdio.h>
  954. X
  955. Xchar *
  956. Xgetcwd(buf, size)
  957. Xchar *buf;
  958. Xint size;
  959. X{
  960. X    FILE *pfp, *popen();
  961. X
  962. X    if (!(pfp = popen("pwd", "r")))
  963. X        return(".");
  964. X
  965. X    fgets(buf, size, pfp);
  966. X    pclose(pfp);
  967. X                    /* zap the new line */
  968. X    buf[strlen(buf)-1] = NULL;
  969. X    return(buf);
  970. X}
  971. SHAR_EOF
  972. if test 387 -ne "`wc -c < 'getcwd.c'`"
  973. then
  974.     echo shar: "error transmitting 'getcwd.c'" '(should have been 387 characters)'
  975. fi
  976. fi
  977. echo shar: "extracting 'getopt.c'" '(1034 characters)'
  978. if test -f 'getopt.c'
  979. then
  980.     echo shar: "will not over-write existing file 'getopt.c'"
  981. else
  982. sed 's/^X//' << \SHAR_EOF > 'getopt.c'
  983. X/*
  984. X * Parse the command line and return option flags and arguments
  985. X */
  986. X
  987. X#include <stdio.h>
  988. X
  989. Xint optind = 1;
  990. Xchar *optarg;
  991. X
  992. Xint
  993. Xgetopt(argc, argv, opts)
  994. Xint argc;
  995. Xchar *argv[];
  996. Xchar *opts;
  997. X{
  998. X    static int sp = 1;
  999. X    int c, strcmp();
  1000. X    char *cp, *strchr();
  1001. X
  1002. X    if (sp == 1) {
  1003. X        if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0')
  1004. X            return(EOF);
  1005. X        else if (strcmp(argv[optind], "--") == NULL) {
  1006. X            optind++;
  1007. X            return(EOF);
  1008. X        }
  1009. X    }
  1010. X    c = argv[optind][sp];
  1011. X    if (c == ':' || (cp=strchr(opts, c)) == NULL) {
  1012. X        fprintf(stderr, "%s: illegal option '%c'\n", argv[0], c);
  1013. X        if (argv[optind][++sp] == '\0') {
  1014. X            optind++;
  1015. X            sp = 1;
  1016. X        }
  1017. X        return('?');
  1018. X    }
  1019. X    if (*++cp == ':') {
  1020. X        if (argv[optind][sp+1] != '\0')
  1021. X            optarg = &argv[optind++][sp+1];
  1022. X        else if (++optind >= argc) {
  1023. X            fprintf(stderr, "%s: option '%c' requires an argument\n", argv[0], c);
  1024. X            sp = 1;
  1025. X            return('?');
  1026. X        } else
  1027. X            optarg = argv[optind++];
  1028. X        sp = 1;
  1029. X    } else {
  1030. X        if (argv[optind][++sp] == '\0') {
  1031. X            sp = 1;
  1032. X            optind++;
  1033. X        }
  1034. X        optarg = NULL;
  1035. X    }
  1036. X    return(c);
  1037. X}
  1038. SHAR_EOF
  1039. if test 1034 -ne "`wc -c < 'getopt.c'`"
  1040. then
  1041.     echo shar: "error transmitting 'getopt.c'" '(should have been 1034 characters)'
  1042. fi
  1043. fi
  1044. echo shar: "extracting 'help.c'" '(1802 characters)'
  1045. if test -f 'help.c'
  1046. then
  1047.     echo shar: "will not over-write existing file 'help.c'"
  1048. else
  1049. sed 's/^X//' << \SHAR_EOF > 'help.c'
  1050. X/*
  1051. X * Display the help screen.  Press any key to continue.  If the ascii_hot
  1052. X * string is more than 4 characters wide, this screen will look silly.
  1053. X * Maybe one day, this will also contain page-full descriptions of each
  1054. X * command.
  1055. X */
  1056. X
  1057. X#include <stdio.h>
  1058. X#include <curses.h>
  1059. X#include "config.h"
  1060. X#include "misc.h"
  1061. X
  1062. Xvoid
  1063. Xhelp_screen(hot)
  1064. Xchar *hot;
  1065. X{
  1066. X    extern int fd;
  1067. X    WINDOW *h_win, *newwin();
  1068. X
  1069. X    h_win = newwin(17, 80, 0, 0);
  1070. X
  1071. X    mvwattrstr(h_win, 1, 29, A_BOLD, "P C O M M       H E L P\n");
  1072. X    horizontal(h_win, 2, 0, 80);
  1073. X    mvwattrstr(h_win, 4, 0, A_BOLD, "       Major Functions          Utility Functions         File Functions\n\n");
  1074. X    mvwprintw(h_win,  6,  2, "Dialing Directory.%4.4s-D  Program Info ....%4.4s-I  Send Files ....%4.4s-<up>", hot, hot, hot);
  1075. X    mvwprintw(h_win,  7,  2, "Auto Redial ......%4.4s-R  Setup Screen ....%4.4s-S  Receive Files .%4.4s-<down>", hot, hot, hot);
  1076. X    mvwprintw(h_win,  8,  2, "Keyboard Macros ..%4.4s-M  Change Directory.%4.4s-B  Pass Thru Mode.%4.4s-T", hot, hot, hot);
  1077. X    mvwprintw(h_win,  9,  2, "Line Settings ....%4.4s-P  Clear Screen ....%4.4s-C  Directory .....%4.4s-F", hot, hot, hot);
  1078. X    mvwprintw(h_win, 10,  2, "Exit Pcomm .......%4.4s-X  Toggle Duplex ...%4.4s-E  Screen Dump ...%4.4s-G", hot, hot, hot);
  1079. X    mvwprintw(h_win, 11,  2, "Unix Gateway .....%4.4s-4  Hang Up Phone ...%4.4s-H  Start Data Log.%4.4s-1", hot, hot, hot);
  1080. X    mvwprintw(h_win, 12, 28, "Printer On/Off ..%4.4s-L  Toggle Log ....%4.4s-2", hot, hot);
  1081. X    mvwprintw(h_win, 13, 28, "Toggle CR-CR/LF .%4.4s-3", hot);
  1082. X    mvwprintw(h_win, 14, 28, "Break Key .......%4.4s-7", hot);
  1083. X
  1084. X    box(h_win, VERT, HORZ);
  1085. X    mvwaddstr(h_win, 16, 26, " Press any key to continue ");
  1086. X    wmove(h_win, 16, 79);
  1087. X    wrefresh(h_win);
  1088. X
  1089. X    wgetch(h_win);
  1090. X    if (fd == -1) {
  1091. X        werase(h_win);
  1092. X        wrefresh(h_win);
  1093. X    }
  1094. X    delwin(h_win);
  1095. X    return;
  1096. X}
  1097. SHAR_EOF
  1098. if test 1802 -ne "`wc -c < 'help.c'`"
  1099. then
  1100.     echo shar: "error transmitting 'help.c'" '(should have been 1802 characters)'
  1101. fi
  1102. fi
  1103. echo shar: "extracting 'info.c'" '(1532 characters)'
  1104. if test -f 'info.c'
  1105. then
  1106.     echo shar: "will not over-write existing file 'info.c'"
  1107. else
  1108. sed 's/^X//' << \SHAR_EOF > 'info.c'
  1109. X/*
  1110. X * Display the initial welcome screen (to include all of the proper
  1111. X * acknowledgements).  Press any key to continue.
  1112. X */
  1113. X
  1114. X#define VERSION "1.1"
  1115. X#define DATE    "21 Aug 88"
  1116. X
  1117. X#include <stdio.h>
  1118. X#include <curses.h>
  1119. X
  1120. Xvoid
  1121. Xinfo(delay)
  1122. Xint delay;
  1123. X{
  1124. X    extern int fd;
  1125. X    WINDOW *w_win, *newwin();
  1126. X    char buf[80];
  1127. X                    /* display the welcome screen */
  1128. X    w_win = newwin(23, 80, 0, 0);
  1129. X    mvwaddstr(w_win, 3, 18, "PPPPPP    CCCC    OOOO    MM   MM   MM   MM");
  1130. X    mvwaddstr(w_win, 4, 18, "P    P   C       O    O   M M M M   M M M M");
  1131. X    mvwaddstr(w_win, 5, 18, "PPPPPP   C       O    O   M  M  M   M  M  M");
  1132. X    mvwaddstr(w_win, 6, 18, "P        C       O    O   M     M   M     M");
  1133. X    mvwaddstr(w_win, 7, 18, "P         CCCC    OOOO    M     M   M     M");
  1134. X
  1135. X    sprintf(buf, ">>> Pcomm Version %s <<<", VERSION);
  1136. X    mvwaddstr(w_win, 10, (80-strlen(buf))/2, buf);
  1137. X    sprintf(buf, "Release date: %s", DATE);
  1138. X    mvwaddstr(w_win, 11, (80-strlen(buf))/2, buf);
  1139. X
  1140. X    mvwaddstr(w_win, 13, 8, "Pcomm is a public domain telecommunication program for Unix that");
  1141. X    mvwaddstr(w_win, 14, 8, "is designed to operate similar to the MSDOS program, ProComm.");
  1142. X    mvwaddstr(w_win, 15, 8, "ProComm (TM) is copyrighted by Datastorm Technologies, Inc.");
  1143. X    mvwaddstr(w_win, 19, 45, "Emmet P. Gray");
  1144. X    mvwaddstr(w_win, 20, 45, "...!uunet!uiucuxc!fthood!egray");
  1145. X    wmove(w_win, 22, 79);
  1146. X    wrefresh(w_win);
  1147. X                    /* Delay so you can read the herald */
  1148. X    if (delay)
  1149. X        wait_key(w_win, 5);
  1150. X    else
  1151. X        wgetch(w_win);
  1152. X
  1153. X    if (fd == -1) {
  1154. X        werase(w_win);
  1155. X        wrefresh(w_win);
  1156. X    }
  1157. X    delwin(w_win);
  1158. X    return;
  1159. X}
  1160. SHAR_EOF
  1161. if test 1532 -ne "`wc -c < 'info.c'`"
  1162. then
  1163.     echo shar: "error transmitting 'info.c'" '(should have been 1532 characters)'
  1164. fi
  1165. fi
  1166. echo shar: "extracting 'init.c'" '(2944 characters)'
  1167. if test -f 'init.c'
  1168. then
  1169.     echo shar: "will not over-write existing file 'init.c'"
  1170. else
  1171. sed 's/^X//' << \SHAR_EOF > 'init.c'
  1172. X/*
  1173. X * Display the welcome screen and find the Pcomm support files.  Returns a
  1174. X * pointer to the STATUS structure.  All errors are fatal.
  1175. X */
  1176. X
  1177. X#include <stdio.h>
  1178. X#include <curses.h>
  1179. X#include "config.h"
  1180. X#ifdef SHAREDMEM
  1181. X#include <sys/types.h>
  1182. X#include <sys/ipc.h>
  1183. X#include <sys/shm.h>
  1184. X#endif /* SHAREDMEM */
  1185. X#include "misc.h"
  1186. X#include "status.h"
  1187. X
  1188. Xstruct STATUS *
  1189. Xinit(short_cut)
  1190. Xchar *short_cut;
  1191. X{
  1192. X    char *mktemp(), *strcpy();
  1193. X    struct STATUS *s_ptr;
  1194. X    void info();
  1195. X#ifdef SHAREDMEM
  1196. X    int i, j, mode;
  1197. X    extern int shm_id;
  1198. X    char *shmat();
  1199. X    void exit();
  1200. X
  1201. X    /*
  1202. X     * Since the "pcomm_input" program does not run set-user/group-id
  1203. X     * the mode must be set so the effective ID can read/write to the
  1204. X     * shared memory segment.  Kinda strange... real ID's aren't used.
  1205. X     */
  1206. X#ifdef SETUGID
  1207. X    mode = 0666;
  1208. X#else /* SETUGID */
  1209. X    mode = 0600;
  1210. X#endif /* SETUGID */
  1211. X                    /* create a shared memory segment */
  1212. X    shm_id = shmget(IPC_PRIVATE, sizeof (struct STATUS),  mode|IPC_CREAT|IPC_EXCL|IPC_NOWAIT);
  1213. X    if (shm_id < 0) {
  1214. X        endwin();
  1215. X        perror("shmget");
  1216. X        exit(1);
  1217. X    }
  1218. X    s_ptr = (struct STATUS *) shmat(shm_id, (char *) 0, 0);
  1219. X    if ((int) s_ptr == -1) {
  1220. X        endwin();
  1221. X        perror("shmat");
  1222. X        exit(1);
  1223. X    }
  1224. X#else /* SHAREDMEM */
  1225. X    static struct STATUS s;
  1226. X    s_ptr = &s;
  1227. X#endif /* SHAREDMEM */
  1228. X                    /* some defaults */
  1229. X    s_ptr->fd = -1;
  1230. X    s_ptr->add_lf = 0;
  1231. X    s_ptr->log = 0;
  1232. X    s_ptr->print = 0;
  1233. X    strcpy(s_ptr->log_path, "NOT_DEFINED");
  1234. X#ifdef SHAREDMEM
  1235. X    s_ptr->clr = 0;
  1236. X    s_ptr->row = 0;
  1237. X    s_ptr->col = 0;
  1238. X    for (i=0; i<LINES; i++) {
  1239. X        for (j=0; j<COLS; j++)
  1240. X            s_ptr->vs[i][j] = ' ';
  1241. X        s_ptr->vs[i][COLS] = NULL;
  1242. X    }
  1243. X#else /* SHAREDMEM */
  1244. X    strcpy(s_ptr->vs_path, mktemp("/tmp/pcommXXXXXX"));
  1245. X#endif /* SHAREDMEM */
  1246. X                    /* display herald if no short-cut */
  1247. X    if (short_cut == NULL)
  1248. X        info(1);
  1249. X
  1250. X    erase();
  1251. X    refresh();
  1252. X    return(s_ptr);
  1253. X}
  1254. X
  1255. X/*
  1256. X * Search the extra directory (supplied on the command line), then the
  1257. X * directory in the PCOMM environmental variable, then the current working
  1258. X * directory, and lastly, the default directory.
  1259. X */
  1260. X
  1261. Xchar *
  1262. Xfindfile(extra, name)
  1263. Xchar *extra, *name;
  1264. X{
  1265. X    int i;
  1266. X    char *pcomm, *getenv(), *path, pbuf[200], *getcwd(), *strdup();
  1267. X    char temp[200];
  1268. X
  1269. X                    /* see if PCOMM variable is set */
  1270. X    pcomm = getenv("PCOMM");
  1271. X    if (pcomm == NULL || *pcomm == NULL)
  1272. X        pcomm = NULL;
  1273. X    else {
  1274. X                    /* zap the trailing separator */
  1275. X        if (pcomm[strlen(pcomm)-1] == '/')
  1276. X            pcomm[strlen(pcomm)-1] = NULL;
  1277. X    }
  1278. X
  1279. X    for (i=0; i<4; i++) {
  1280. X                    /* directory search order */
  1281. X        switch (i) {
  1282. X            case 0:        /* extra directory from command line */
  1283. X                path = extra;
  1284. X                break;
  1285. X            case 1:        /* PCOMM environmental variable */
  1286. X                path = pcomm;
  1287. X                break;
  1288. X            case 2:        /* current working directory */
  1289. X                path = getcwd(pbuf, 200);
  1290. X                break;
  1291. X            case 3:        /* Pcomm's default directory */
  1292. X                path = DEFAULT_DIR;
  1293. X                break;
  1294. X        }
  1295. X        if (path == NULL)
  1296. X            continue;
  1297. X
  1298. X        sprintf(temp, "%s/%s", path, name);
  1299. X                    /* read permission checked */
  1300. X        if (!access(temp, 4))
  1301. X            return(strdup(temp));
  1302. X    }
  1303. X    return(NULL);
  1304. X}
  1305. SHAR_EOF
  1306. if test 2944 -ne "`wc -c < 'init.c'`"
  1307. then
  1308.     echo shar: "error transmitting 'init.c'" '(should have been 2944 characters)'
  1309. fi
  1310. fi
  1311. echo shar: "extracting 'input.c'" '(10147 characters)'
  1312. if test -f 'input.c'
  1313. then
  1314.     echo shar: "will not over-write existing file 'input.c'"
  1315. else
  1316. sed 's/^X//' << \SHAR_EOF > 'input.c'
  1317. X/*
  1318. X * The input routines.  This program runs as a child process to the
  1319. X * Pcomm program.
  1320. X */
  1321. X
  1322. X#define CLIST 64
  1323. X
  1324. X#include <stdio.h>
  1325. X#include <signal.h>
  1326. X#include <setjmp.h>
  1327. X#include "config.h"
  1328. X#ifdef SHAREDMEM
  1329. X#include <sys/types.h>
  1330. X#include <sys/ipc.h>
  1331. X#include <sys/shm.h>
  1332. X#endif /* SHAREDMEM */
  1333. X#define MAIN
  1334. X#include "misc.h"
  1335. X#include "status.h"
  1336. X#include "vcs.h"
  1337. X
  1338. Xjmp_buf i_jmp;
  1339. Xint vcs_param[NUM_VCS][5];        /* positional parameters */
  1340. Xint vcs_opt[NUM_VCS][10];        /* options unique to each vcs */
  1341. Xint vcs_codes[NUM_VCS][VCS_SIZE];    /* the vcs codes */
  1342. Xint vcs_leadin[NUM_VCS];        /* unique list of lead-in characters */
  1343. Xint num_leadin;                /* length of lead-in list */
  1344. Xint hold, max_row, max_col, skip_row;
  1345. XFILE *logfp, *lprfp;
  1346. Xstruct STATUS *status;
  1347. X
  1348. X#ifdef SHAREDMEM
  1349. X#define VROW    status->row
  1350. X#define VCOL    status->col
  1351. X#define VS    status->vs
  1352. X#else /* SHAREDMEM */
  1353. Xint VROW, VCOL;
  1354. Xchar VS[MAX_ROW][MAX_COL+2];
  1355. Xstruct STATUS s;
  1356. X#endif /* SHAREDMEM */
  1357. X
  1358. X/*
  1359. X * Read the serial port and write the characters to the screen.  Watch
  1360. X * for signals from the parent process to toggle the fancy options.
  1361. X * Writes the characters received to a virtual screen buffer.
  1362. X */
  1363. X
  1364. Xmain(argc, argv)
  1365. Xint argc;
  1366. Xchar *argv[];
  1367. X{
  1368. X    FILE *popen();
  1369. X    int got_sig();
  1370. X    char c, *strcpy();
  1371. X    void _exit(), exit(), vcs_table();
  1372. X#ifdef SHAREDMEM
  1373. X    int shm_id;
  1374. X    char *shmat();
  1375. X#endif /* SHAREDMEM */
  1376. X                    /* set the trap for the signals */
  1377. X    signal(SIGALRM, SIG_IGN);
  1378. X    signal(SIGHUP,  SIG_IGN);
  1379. X    signal(SIGQUIT, SIG_IGN);
  1380. X    signal(SIGUSR1, got_sig);
  1381. X    signal(SIGUSR2, got_sig);
  1382. X    signal(SIGINT,  got_sig);
  1383. X    signal(SIGTERM, got_sig);
  1384. X                    /* unbuffered output */
  1385. X    setbuf(stdout, (char *) NULL);
  1386. X                    /* for the curious... */
  1387. X    if (argc == 1) {
  1388. X        fprintf(stderr, "This is the input routine for the Pcomm program\n");
  1389. X        fprintf(stderr, "It is not designed to be run as a separate program\n");
  1390. X        exit(1);
  1391. X    }
  1392. X#ifdef SHAREDMEM
  1393. X    shm_id = atoi(argv[1]);
  1394. X    status = (struct STATUS *) shmat(shm_id, (char *) 0, 0);
  1395. X    if ((int) status == -1) {
  1396. X        perror("shmat");
  1397. X        _exit(1);
  1398. X    }
  1399. X#else /* SHAREDMEM */
  1400. X    status = &s;
  1401. X#endif /* SHAREDMEM */
  1402. X                    /* load the VCS table */
  1403. X    vcs_table();
  1404. X    if (max_row > MAX_ROW)
  1405. X        max_row = MAX_ROW;
  1406. X    if (max_col > MAX_COL)
  1407. X        max_col = MAX_COL;
  1408. X                    /* parse the command line */
  1409. X#ifndef SHAREDMEM
  1410. X    status->fd = atoi(argv[1]);
  1411. X    status->add_lf = atoi(argv[2]);
  1412. X    status->log = atoi(argv[3]);
  1413. X    status->print = atoi(argv[4]);
  1414. X    strcpy(status->log_path, argv[5]);
  1415. X    strcpy(status->vs_path, argv[6]);
  1416. X#endif /* SHAREDMEM */
  1417. X
  1418. X    skip_row = 0;
  1419. X#ifdef SHAREDMEM
  1420. X    if (status->clr)
  1421. X        skip_row = 1;
  1422. X#else /* SHAREDMEM */
  1423. X                    /* read previous screen */
  1424. X    if (!access(status->vs_path, 0))
  1425. X        read_vs();
  1426. X    else
  1427. X        skip_row = 1;
  1428. X#endif /* SHAREDMEM */
  1429. X
  1430. X    hold = 0;
  1431. X                    /* start up file pointers */
  1432. X    lprfp = (FILE *) NULL;
  1433. X    logfp = (FILE *) NULL;
  1434. X
  1435. X    switch (setjmp(i_jmp)) {
  1436. X        case 0:            /* no signal */
  1437. X            break;
  1438. X        case 1:            /* toggle the data logging */
  1439. X            status->log = status->log ? 0 : 1;
  1440. X            break;
  1441. X        case 2:            /* toggle the printer */
  1442. X            status->print = status->print ? 0 : 1;
  1443. X            break;
  1444. X        case 3:            /* suspend the input */
  1445. X            hold = hold ? 0 : 1;
  1446. X#ifndef SHAREDMEM
  1447. X            if (hold)
  1448. X                write_vs();
  1449. X#endif /* SHAREDMEM */
  1450. X            break;
  1451. X        case 4:            /* clean up and go home */
  1452. X            if (status->log)
  1453. X                fclose(logfp);
  1454. X            if (status->print) {
  1455. X                putc('\f', lprfp);
  1456. X                pclose(lprfp);
  1457. X            }
  1458. X#ifdef SHAREDMEM
  1459. X                    /* detach shared memory */
  1460. X            shmdt((char *) status);
  1461. X#endif /* SHAREDMEM */
  1462. X            _exit(0);
  1463. X            break;
  1464. X    }
  1465. X                    /* any signal will awaken pause() */
  1466. X    if (hold)
  1467. X        pause();
  1468. X                    /* open or close the printer */
  1469. X    if (status->print && lprfp == NULL)
  1470. X        lprfp = popen(LPR, "w");
  1471. X
  1472. X    if (!status->print && lprfp != NULL) {
  1473. X        putc('\f', lprfp);
  1474. X        pclose(lprfp);
  1475. X        lprfp = (FILE *) NULL;
  1476. X    }
  1477. X                    /* open or close the log file */
  1478. X    if (status->log && logfp == NULL) {
  1479. X        if (strcmp(status->log_path, "NOT_DEFINED")) {
  1480. X            if (!(logfp = fopen(status->log_path, "a")))
  1481. X                status->log = 0;
  1482. X        }
  1483. X        else
  1484. X            status->log = 0;
  1485. X    }
  1486. X    if (!status->log && logfp != NULL) {
  1487. X        fclose(logfp);
  1488. X        logfp = (FILE *) NULL;
  1489. X    }
  1490. X
  1491. X#ifdef SHAREDMEM
  1492. X    if (status->clr) {
  1493. X        status->clr = 0;
  1494. X        vs_clear();
  1495. X    }
  1496. X#else /* SHAREDMEM */
  1497. X                    /* clear if vs_path doesn't exist */
  1498. X    if (access(status->vs_path, 0))
  1499. X        vs_clear();
  1500. X#endif /* SHAREDMEM */
  1501. X    /*
  1502. X     * The very first screen we see after dialing has the "Connected to..."
  1503. X     * message at row 0, therefore we start our virtual screen at row 1.
  1504. X     */
  1505. X    if (skip_row) {
  1506. X        skip_row = 0;
  1507. X        VROW = 1;
  1508. X    }
  1509. X
  1510. X    while (1) {
  1511. X        if ((int) (c = readbyte()) <= 0)
  1512. X            continue;
  1513. X                    /* send to logfile */
  1514. X        if (status->log) {
  1515. X            if (c == '\r' && status->add_lf)
  1516. X                putc('\n', logfp);
  1517. X                    /* no carriage returns in logfile */
  1518. X            if (c != '\r')
  1519. X                putc(c, logfp);
  1520. X        }
  1521. X                    /* send to printer too? */
  1522. X        if (status->print)
  1523. X            putc(c, lprfp);
  1524. X
  1525. X                    /* put a char in virtual screen */
  1526. X        vs_putchar(c);
  1527. X
  1528. X        putchar(c);
  1529. X                    /* add LF to CR? */
  1530. X        if (c == '\r' && status->add_lf)
  1531. X            putchar('\n');
  1532. X    }
  1533. X}
  1534. X
  1535. X/*
  1536. X * Figure out which signal we just received, and fix the return code of
  1537. X * the setjmp function above to the proper value.
  1538. X */
  1539. X
  1540. Xint
  1541. Xgot_sig(sig)
  1542. Xint sig;
  1543. X{
  1544. X    void longjmp();
  1545. X    switch (sig) {
  1546. X        case SIGUSR1:
  1547. X            signal(SIGUSR1, got_sig);
  1548. X            longjmp(i_jmp, 1);
  1549. X        case SIGUSR2:
  1550. X            signal(SIGUSR2, got_sig);
  1551. X            longjmp(i_jmp, 2);
  1552. X        case SIGINT:
  1553. X            signal(SIGINT, got_sig);
  1554. X            longjmp(i_jmp, 3);
  1555. X        case SIGTERM:
  1556. X            signal(SIGTERM, got_sig);
  1557. X            longjmp(i_jmp, 4);
  1558. X    }
  1559. X}
  1560. X
  1561. X/*
  1562. X * Put a character in the virtual screen.  This routine saves incoming
  1563. X * characters in a two dimensional buffer designed to mimic the real
  1564. X * screen.
  1565. X */
  1566. X
  1567. Xint
  1568. Xvs_putchar(c)
  1569. Xchar c;
  1570. X{
  1571. X    register int j, i;
  1572. X    int tab_stop;
  1573. X
  1574. X    switch (vcs_filter(c)) {
  1575. X        case MAYBE:        /* wait and see... */
  1576. X            break;
  1577. X        case 256+HOME:        /* home virtual screen "cursor" */
  1578. X            VROW = 0;
  1579. X            VCOL = 0;
  1580. X            break;
  1581. X        case 256+CLR_EOL:    /* clear to end of line */
  1582. X            for (i=VCOL; i<max_col; i++)
  1583. X                VS[VROW][i] = ' ';
  1584. X            break;
  1585. X        case 256+CLR_EOS:    /* clear to end of screen */
  1586. X            for (j=VCOL; j<max_col; j++)
  1587. X                VS[VROW][j] = ' ';
  1588. X            for (i=VROW+1; i<max_row; i++) {
  1589. X                for (j=0; j<max_col; j++)
  1590. X                    VS[i][j] = ' ';
  1591. X            }
  1592. X            break;
  1593. X        case 256+CLEAR:        /* clear all and home "cursor" */
  1594. X            for (i=0; i<max_row; i++) {
  1595. X                for (j=0; j<max_col; j++)
  1596. X                    VS[i][j] = ' ';
  1597. X            }
  1598. X            VROW = 0;
  1599. X            VCOL = 0;
  1600. X            break;
  1601. X        case 256+MV_UP:        /* move "cursor" up */
  1602. X            VROW--;
  1603. X            if (VROW < 0)
  1604. X                VROW = 0;
  1605. X            break;
  1606. X        case 256+MV_DOWN:    /* move "cursor" down */
  1607. X            VROW++;
  1608. X            if (VROW >= max_row)
  1609. X                VROW = max_row -1;
  1610. X            break;
  1611. X        case 256+MV_RIGHT:    /* move "cursor" right */
  1612. X            VCOL++;
  1613. X            if (VCOL >= max_col)
  1614. X                VCOL = max_col -1;
  1615. X            break;
  1616. X        case 256+MV_LEFT:    /* move "cursor" left */
  1617. X        case BS:        /* non destructive back space */
  1618. X            VCOL--;
  1619. X            if (VCOL < 0)
  1620. X                VCOL = 0;
  1621. X            break;
  1622. X        case 256+MV_DIRECT:    /* direct cursor movement */
  1623. X            VROW = vcs_param[MV_DIRECT][0];
  1624. X            VCOL = vcs_param[MV_DIRECT][1];
  1625. X
  1626. X                    /* if "add one" and "decimal" */
  1627. X            if (vcs_opt[MV_DIRECT][0] && vcs_opt[MV_DIRECT][1]) {
  1628. X                VROW--;
  1629. X                VCOL--;
  1630. X            }
  1631. X                    /* if "character" */
  1632. X            if (vcs_opt[MV_DIRECT][2]) {
  1633. X                    /* if "add offset" */
  1634. X                if (vcs_opt[MV_DIRECT][3]) {
  1635. X                    VROW -= vcs_opt[MV_DIRECT][5];
  1636. X                    VCOL -= vcs_opt[MV_DIRECT][5];
  1637. X                }
  1638. X                    /* if "subtract offset" */
  1639. X                if (vcs_opt[MV_DIRECT][4]) {
  1640. X                    VROW += vcs_opt[MV_DIRECT][5];
  1641. X                    VCOL += vcs_opt[MV_DIRECT][5];
  1642. X                }
  1643. X                VROW--;
  1644. X                VCOL--;
  1645. X            }
  1646. X            break;
  1647. X        case '\t':        /* tab character */
  1648. X            tab_stop = VCOL + 8 - (VCOL % 8);
  1649. X                    /* if wrap around */
  1650. X            if (tab_stop >= max_col) {
  1651. X                    /* spaces up to eol */
  1652. X                for (; VCOL<max_col; VCOL++)
  1653. X                    VS[VROW][VCOL] = ' ';
  1654. X                VROW++;
  1655. X                if (VROW >= max_row)
  1656. X                    vs_scroll();
  1657. X
  1658. X                    /* the remainder of the tab */
  1659. X                VCOL = tab_stop - max_col;
  1660. X            }
  1661. X            else {
  1662. X                for (; VCOL<tab_stop; VCOL++)
  1663. X                    VS[VROW][VCOL] = ' ';
  1664. X            }
  1665. X            break;
  1666. X        case '\r':        /* carriage return */
  1667. X            VCOL = 0;
  1668. X            if (!status->add_lf)
  1669. X                break;
  1670. X            /* fall thru...*/
  1671. X        case '\n':        /* line feed */
  1672. X            VROW++;
  1673. X            if (VROW >= max_row)
  1674. X                vs_scroll();
  1675. X            break;
  1676. X        default:        /* a normal character */
  1677. X            VS[VROW][VCOL] = c;
  1678. X            VCOL++;
  1679. X                    /* wrap around */
  1680. X            if (VCOL >= max_col) {
  1681. X                VCOL = 0;
  1682. X                VROW++;
  1683. X                if (VROW >= max_row)
  1684. X                    vs_scroll();
  1685. X            }
  1686. X            break;
  1687. X    }
  1688. X    return(0);
  1689. X}
  1690. X
  1691. X#ifndef SHAREDMEM
  1692. X/*
  1693. X * Save the virtual screen to a file.
  1694. X */
  1695. X
  1696. Xint
  1697. Xwrite_vs()
  1698. X{
  1699. X    FILE *fp;
  1700. X    register int i;
  1701. X
  1702. X    if (!(fp = fopen(status->vs_path, "w")))
  1703. X        return(1);
  1704. X                    /* current x y coordinates */
  1705. X    fprintf(fp, "%d,%d\n", VROW, VCOL);
  1706. X
  1707. X    for (i=0; i<max_row; i++) {
  1708. X        VS[i][max_col] = NULL;
  1709. X        fprintf(fp, "%s\n", VS[i]);
  1710. X    }
  1711. X    fclose(fp);
  1712. X    return(0);
  1713. X}
  1714. X
  1715. X/*
  1716. X * Get the virtual screen image from the file.  Since input() gets
  1717. X * killed from time to time, the vs_path file is the only way to retain
  1718. X * the screen image.
  1719. X */
  1720. X
  1721. Xint
  1722. Xread_vs()
  1723. X{
  1724. X    FILE *fp;
  1725. X    register int i;
  1726. X    char buf[10];
  1727. X                /* in case the fopen fails... */
  1728. X    VROW = 0;
  1729. X    VCOL = 0;
  1730. X                /* not guaranteed to exist yet */
  1731. X    if (!(fp = fopen(status->vs_path, "r")))
  1732. X        return(1);
  1733. X                /* get the x, y coordinates */
  1734. X    fgets(buf, 10, fp);
  1735. X    scanf(buf, "%d,%d\n", VROW, VCOL);
  1736. X
  1737. X                /* read the file into the vs array */
  1738. X    for (i=0; i<max_row; i++) {
  1739. X        fgets(VS[i], MAX_COL+2, fp);
  1740. X        VS[i][max_col] = NULL;
  1741. X    }
  1742. X    fclose(fp);
  1743. X    return(0);
  1744. X}
  1745. X#endif /* SHAREDMEM */
  1746. X
  1747. X/*
  1748. X * If the user clears the screen with the ^A-C command, the input
  1749. X * has to be in sync.
  1750. X */
  1751. X
  1752. Xint
  1753. Xvs_clear()
  1754. X{
  1755. X    register int j, i;
  1756. X
  1757. X    for (i=0; i<max_row; i++) {
  1758. X        VS[i][max_col] = NULL;
  1759. X        for (j=0; j<max_col; j++)
  1760. X            VS[i][j] = ' ';
  1761. X    }
  1762. X                    /* home the "cursor" */
  1763. X    VROW = 0;
  1764. X    VCOL = 0;
  1765. X    return(0);
  1766. X}
  1767. X
  1768. X/*
  1769. X * Do a software scroll on the virtual screen.  Does not alter the
  1770. X * "col" variable.
  1771. X */
  1772. X
  1773. Xint
  1774. Xvs_scroll()
  1775. X{
  1776. X    register int i;
  1777. X    char *strcpy();
  1778. X                    /* move 'em up 1 line */
  1779. X    for (i=0; i<max_row-1; i++)
  1780. X        strcpy(VS[i], VS[i+1]);
  1781. X                    /* clear the bottom line */
  1782. X    for (i=0; i<max_col; i++)
  1783. X        VS[max_row-1][i] = ' ';
  1784. X
  1785. X    VROW = max_row -1;
  1786. X    return(0);
  1787. X}
  1788. X
  1789. X/*
  1790. X * Do a buffered read from the serial port.
  1791. X */
  1792. X
  1793. Xint
  1794. Xreadbyte()
  1795. X{
  1796. X    static char buf[CLIST];
  1797. X    static char *bufp = buf;
  1798. X    static int n = 0;
  1799. X
  1800. X    if (n <= 0) {
  1801. X        if ((n = read(status->fd, buf, CLIST)) <= 0)
  1802. X            return(-1);
  1803. X        bufp = buf;
  1804. X    }
  1805. X    while (--n >= 0)
  1806. X        return(*bufp++ & 0xff);
  1807. X    return(-1);
  1808. X}
  1809. SHAR_EOF
  1810. if test 10147 -ne "`wc -c < 'input.c'`"
  1811. then
  1812.     echo shar: "error transmitting 'input.c'" '(should have been 10147 characters)'
  1813. fi
  1814. fi
  1815. echo shar: "extracting 'line_set.c'" '(1944 characters)'
  1816. if test -f 'line_set.c'
  1817. then
  1818.     echo shar: "will not over-write existing file 'line_set.c'"
  1819. else
  1820. sed 's/^X//' << \SHAR_EOF > 'line_set.c'
  1821. X/*
  1822. X * Change the communication line settings to the new values.
  1823. X */
  1824. X
  1825. X#include <stdio.h>
  1826. X#include <termio.h>
  1827. X#include "dial_dir.h"
  1828. X#include "param.h"
  1829. X
  1830. Xvoid
  1831. Xline_set()
  1832. X{
  1833. X    extern int fd;
  1834. X    struct termio tbuf;
  1835. X
  1836. X    /*
  1837. X     * The manual dial entry also serves to store the previous
  1838. X     * line settings.  How else would the manual dial entry
  1839. X     * know what line setting to use?
  1840. X     */
  1841. X    if (dir->d_cur != 0) {
  1842. X        dir->baud[0] = dir->baud[dir->d_cur];
  1843. X        dir->parity[0] = dir->parity[dir->d_cur];
  1844. X        dir->dbits[0] = dir->dbits[dir->d_cur];
  1845. X        dir->sbits[0] = dir->sbits[dir->d_cur];
  1846. X    }
  1847. X                    /* nothing to do! */
  1848. X    if (fd == -1)
  1849. X        return;
  1850. X                    /* get the current settings */
  1851. X    ioctl(fd, TCGETA, &tbuf);
  1852. X                    /* set some beginning values */
  1853. X    tbuf.c_cc[4] = 1;        /* VMIN */
  1854. X    tbuf.c_cc[5] = 0;        /* VTIME */
  1855. X    tbuf.c_oflag = 0;
  1856. X    tbuf.c_iflag = 0;
  1857. X    tbuf.c_cflag = (CREAD|HUPCL|CLOCAL);
  1858. X    tbuf.c_lflag = 0;
  1859. X
  1860. X    if (*param->flow == 'X')
  1861. X        tbuf.c_iflag |= IXON|IXOFF;
  1862. X                    /* strip high bit? */
  1863. X    if (*param->strip == 'Y')
  1864. X        tbuf.c_iflag |= ISTRIP;
  1865. X                    /* the baud rate */
  1866. X    switch (dir->baud[dir->d_cur]) {
  1867. X        case 300:
  1868. X            tbuf.c_cflag |= B300;
  1869. X            break;
  1870. X        case 1200:
  1871. X            tbuf.c_cflag |= B1200;
  1872. X            break;
  1873. X        case 2400:
  1874. X            tbuf.c_cflag |= B2400;
  1875. X            break;
  1876. X        case 4800:
  1877. X            tbuf.c_cflag |= B4800;
  1878. X            break;
  1879. X        case 9600:
  1880. X            tbuf.c_cflag |= B9600;
  1881. X            break;
  1882. X        case 19200:
  1883. X#ifdef B19200
  1884. X            tbuf.c_cflag |= B19200;
  1885. X#else /* B19200 */
  1886. X#ifdef EXTA
  1887. X            tbuf.c_cflag |= EXTA;
  1888. X#endif /* EXTA */
  1889. X#endif /* B19200 */
  1890. X            break;
  1891. X    }
  1892. X                    /* the parity */
  1893. X    switch (dir->parity[dir->d_cur]) {
  1894. X        case 'N':
  1895. X            break;
  1896. X        case 'O':
  1897. X            tbuf.c_cflag |= (PARENB|PARODD);
  1898. X            break;
  1899. X        case 'E':
  1900. X            tbuf.c_cflag |= PARENB;
  1901. X            break;
  1902. X    }
  1903. X                    /* the data bits */
  1904. X    if (dir->dbits[dir->d_cur] == 8)
  1905. X        tbuf.c_cflag |= CS8;
  1906. X    else
  1907. X        tbuf.c_cflag |= CS7;
  1908. X                    /* the stop bits */
  1909. X    if (dir->sbits[dir->d_cur] == 2)
  1910. X        tbuf.c_cflag |= CSTOPB;
  1911. X
  1912. X                    /* now set 'em! */
  1913. X    ioctl(fd, TCSETA, &tbuf);
  1914. X    ioctl(fd, TCFLSH, 2);
  1915. X    return;
  1916. X}
  1917. SHAR_EOF
  1918. if test 1944 -ne "`wc -c < 'line_set.c'`"
  1919. then
  1920.     echo shar: "error transmitting 'line_set.c'" '(should have been 1944 characters)'
  1921. fi
  1922. fi
  1923. echo shar: "extracting 'list_dir.c'" '(1508 characters)'
  1924. if test -f 'list_dir.c'
  1925. then
  1926.     echo shar: "will not over-write existing file 'list_dir.c'"
  1927. else
  1928. sed 's/^X//' << \SHAR_EOF > 'list_dir.c'
  1929. X/*
  1930. X * Do a shell escape with an "ls" command
  1931. X */
  1932. X
  1933. X#include <stdio.h>
  1934. X#include <curses.h>
  1935. X#include "config.h"
  1936. X#include "misc.h"
  1937. X
  1938. Xvoid
  1939. Xlist_dir()
  1940. X{
  1941. X    extern int fd;
  1942. X    WINDOW *ls_win, *newwin();
  1943. X    FILE *pfp, *n_popen();
  1944. X    int lines, oops;
  1945. X    char *ans, *cwd, *getcwd(), buf[200], *get_str();
  1946. X
  1947. X    ls_win = newwin(6, 70, 8, 5);
  1948. X
  1949. X    cwd = getcwd(buf, 200);
  1950. X
  1951. X    mvwprintw(ls_win, 2, 4, "Current directory: %s", cwd);
  1952. X    mvwaddstr(ls_win, 3, 4, "File spec (wildcards allowed): ");
  1953. X    box(ls_win, VERT, HORZ);
  1954. X
  1955. X    mvwattrstr(ls_win, 0, 3, A_BOLD, " List Directory ");
  1956. X    wmove(ls_win, 3, 35);
  1957. X    wrefresh(ls_win);
  1958. X
  1959. X    if ((ans = get_str(ls_win, 60, "", "")) == NULL) {
  1960. X        if (fd == -1) {
  1961. X            werase(ls_win);
  1962. X            wrefresh(ls_win);
  1963. X        }
  1964. X        delwin(ls_win);
  1965. X        return;
  1966. X    }
  1967. X                    /* popen() an ls */
  1968. X    sprintf(buf, "ls -aC %s", ans);
  1969. X    pfp = n_popen(buf, "r");
  1970. X                    /* make a bigger window */
  1971. X    werase(ls_win);
  1972. X    wrefresh(ls_win);
  1973. X    delwin(ls_win);
  1974. X    ls_win = newwin(LINES-1, COLS, 0, 0);
  1975. X    touchwin(ls_win);
  1976. X
  1977. X    oops = 0;
  1978. X    lines = 0;
  1979. X    while (fgets(buf, BUFSIZ, pfp) != NULL) {
  1980. X        waddstr(ls_win, buf);
  1981. X        lines++;
  1982. X        if (lines == LINES-2) {
  1983. X            lines = 0;
  1984. X            mvwaddstr(ls_win, LINES-2, 28, "Press any key for more");
  1985. X            wrefresh(ls_win);
  1986. X            if (wgetch(ls_win) == ESC) {
  1987. X                oops++;
  1988. X                break;
  1989. X            }
  1990. X            werase(ls_win);
  1991. X            wrefresh(ls_win);
  1992. X        }
  1993. X    }
  1994. X    n_pclose(pfp);
  1995. X
  1996. X    if (!oops) {
  1997. X        mvwaddstr(ls_win, LINES-2, 25, "Press any key to continue");
  1998. X        wrefresh(ls_win);
  1999. X        wgetch(ls_win);
  2000. X    }
  2001. X    if (fd == -1) {
  2002. X        werase(ls_win);
  2003. X        wrefresh(ls_win);
  2004. X    }
  2005. X    delwin(ls_win);
  2006. X    return;
  2007. X}
  2008. SHAR_EOF
  2009. if test 1508 -ne "`wc -c < 'list_dir.c'`"
  2010. then
  2011.     echo shar: "error transmitting 'list_dir.c'" '(should have been 1508 characters)'
  2012. fi
  2013. fi
  2014. echo shar: "extracting 'ls_menu.c'" '(4809 characters)'
  2015. if test -f 'ls_menu.c'
  2016. then
  2017.     echo shar: "will not over-write existing file 'ls_menu.c'"
  2018. else
  2019. sed 's/^X//' << \SHAR_EOF > 'ls_menu.c'
  2020. X/*
  2021. X * Routines for displaying current line settings and prompting for changes.
  2022. X */
  2023. X
  2024. X#include <stdio.h>
  2025. X#include <curses.h>
  2026. X#include "config.h"
  2027. X#include "dial_dir.h"
  2028. X#include "misc.h"
  2029. X#include "param.h"
  2030. X
  2031. X/*
  2032. X * Display the current line settings and prompt for changes.  A return
  2033. X * code of 1 means settings were changed.
  2034. X */
  2035. X
  2036. Xint
  2037. Xls_menu()
  2038. X{
  2039. X    extern int fd;
  2040. X    WINDOW *l_win, *newwin();
  2041. X    int num, ret_code;
  2042. X    void disp_settings();
  2043. X
  2044. X    l_win = newwin(20, 47, 0, 16);
  2045. X
  2046. X    mvwattrstr(l_win, 1, 16, A_BOLD, "Line Settings");
  2047. X    horizontal(l_win, 2, 0, 47);
  2048. X    mvwaddstr(l_win, 6, 5, "1)     300,E,7,1     7)     300,N,8,1");
  2049. X    mvwaddstr(l_win, 7, 5, "2)    1200,E,7,1     8)    1200,N,8,1");
  2050. X    mvwaddstr(l_win, 8, 5, "3)    2400,E,7,1     9)    2400,N,8,1");
  2051. X    mvwaddstr(l_win, 9, 5, "4)    4800,E,7,1    10)    4800,N,8,1");
  2052. X    mvwaddstr(l_win, 10, 5, "5)    9600,E,7,1    11)    9600,N,8,1");
  2053. X    mvwaddstr(l_win, 11, 5, "6)   19200,E,7,1    12)   19200,N,8,1");
  2054. X    mvwaddstr(l_win, 13, 4, "Parity        Data Bits       Stop Bits");
  2055. X    mvwaddstr(l_win, 14, 4, "13) Odd       14) 7 bits      16) 1 bit");
  2056. X    mvwaddstr(l_win, 15, 18, "15) 8 bits      17) 2 bits");
  2057. X    mvwaddstr(l_win, 17, 4, "18) Save Changes");
  2058. X    mvwattrstr(l_win, 17, 28, A_BOLD, "YOUR CHOICE:");
  2059. X    wmove(l_win, 17, 41);
  2060. X    box(l_win, VERT, HORZ);
  2061. X
  2062. X    mvwaddstr(l_win, 19, 13, " Press <ESC> to return ");
  2063. X                    /* display current settings */
  2064. X    disp_settings(l_win);
  2065. X    wmove(l_win, 17, 41);
  2066. X    wrefresh(l_win);
  2067. X                    /* get the options */
  2068. X    ret_code = 0;
  2069. X    while ((num = get_num(l_win, 2)) != -1) {
  2070. X        switch (num) {
  2071. X            case 1:
  2072. X                dir->baud[dir->d_cur] = 300;
  2073. X                dir->parity[dir->d_cur] = 'E';
  2074. X                dir->dbits[dir->d_cur] = 7;
  2075. X                dir->sbits[dir->d_cur] = 1;
  2076. X                break;
  2077. X            case 2:
  2078. X                dir->baud[dir->d_cur] = 1200;
  2079. X                dir->parity[dir->d_cur] = 'E';
  2080. X                dir->dbits[dir->d_cur] = 7;
  2081. X                dir->sbits[dir->d_cur] = 1;
  2082. X                break;
  2083. X            case 3:
  2084. X                dir->baud[dir->d_cur] = 2400;
  2085. X                dir->parity[dir->d_cur] = 'E';
  2086. X                dir->dbits[dir->d_cur] = 7;
  2087. X                dir->sbits[dir->d_cur] = 1;
  2088. X                break;
  2089. X            case 4:
  2090. X                dir->baud[dir->d_cur] = 4800;
  2091. X                dir->parity[dir->d_cur] = 'E';
  2092. X                dir->dbits[dir->d_cur] = 7;
  2093. X                dir->sbits[dir->d_cur] = 1;
  2094. X                break;
  2095. X            case 5:
  2096. X                dir->baud[dir->d_cur] = 9600;
  2097. X                dir->parity[dir->d_cur] = 'E';
  2098. X                dir->dbits[dir->d_cur] = 7;
  2099. X                dir->sbits[dir->d_cur] = 1;
  2100. X                break;
  2101. X            case 6:
  2102. X                dir->baud[dir->d_cur] = 19200;
  2103. X                dir->parity[dir->d_cur] = 'E';
  2104. X                dir->dbits[dir->d_cur] = 7;
  2105. X                dir->sbits[dir->d_cur] = 1;
  2106. X                break;
  2107. X            case 7:
  2108. X                dir->baud[dir->d_cur] = 300;
  2109. X                dir->parity[dir->d_cur] = 'N';
  2110. X                dir->dbits[dir->d_cur] = 8;
  2111. X                dir->sbits[dir->d_cur] = 1;
  2112. X                break;
  2113. X            case 8:
  2114. X                dir->baud[dir->d_cur] = 1200;
  2115. X                dir->parity[dir->d_cur] = 'N';
  2116. X                dir->dbits[dir->d_cur] = 8;
  2117. X                dir->sbits[dir->d_cur] = 1;
  2118. X                break;
  2119. X            case 9:
  2120. X                dir->baud[dir->d_cur] = 2400;
  2121. X                dir->parity[dir->d_cur] = 'N';
  2122. X                dir->dbits[dir->d_cur] = 8;
  2123. X                dir->sbits[dir->d_cur] = 1;
  2124. X                break;
  2125. X            case 10:
  2126. X                dir->baud[dir->d_cur] = 4800;
  2127. X                dir->parity[dir->d_cur] = 'N';
  2128. X                dir->dbits[dir->d_cur] = 8;
  2129. X                dir->sbits[dir->d_cur] = 1;
  2130. X                break;
  2131. X            case 11:
  2132. X                dir->baud[dir->d_cur] = 9600;
  2133. X                dir->parity[dir->d_cur] = 'N';
  2134. X                dir->dbits[dir->d_cur] = 8;
  2135. X                dir->sbits[dir->d_cur] = 1;
  2136. X                break;
  2137. X            case 12:
  2138. X                dir->baud[dir->d_cur] = 19200;
  2139. X                dir->parity[dir->d_cur] = 'N';
  2140. X                dir->dbits[dir->d_cur] = 8;
  2141. X                dir->sbits[dir->d_cur] = 1;
  2142. X                break;
  2143. X            case 13:
  2144. X                dir->parity[dir->d_cur] = 'O';
  2145. X                break;
  2146. X            case 14:
  2147. X                dir->dbits[dir->d_cur] = 7;
  2148. X                break;
  2149. X            case 15:
  2150. X                dir->dbits[dir->d_cur] = 8;
  2151. X                break;
  2152. X            case 16:
  2153. X                dir->sbits[dir->d_cur] = 1;
  2154. X                break;
  2155. X            case 17:
  2156. X                dir->sbits[dir->d_cur] = 2;
  2157. X                break;
  2158. X            case 18:
  2159. X                    /* copy the current settings */
  2160. X                param->d_baud = dir->baud[dir->d_cur];
  2161. X                param->d_parity = dir->parity[dir->d_cur];
  2162. X                param->d_dbits = dir->dbits[dir->d_cur];
  2163. X                param->d_sbits = dir->sbits[dir->d_cur];
  2164. X                /*
  2165. X                 * We've changed the values in memory even
  2166. X                 * if the update fails.
  2167. X                 */
  2168. X                if (up_param()) {
  2169. X                    touchwin(l_win);
  2170. X                    wrefresh(l_win);
  2171. X                }
  2172. X                break;
  2173. X            default:
  2174. X                beep();
  2175. X        }
  2176. X        ret_code++;
  2177. X        disp_settings(l_win);
  2178. X        mvwaddstr(l_win, 17, 41, "    ");
  2179. X        wmove(l_win, 17, 41);
  2180. X        wrefresh(l_win);
  2181. X    }
  2182. X    if (fd == -1) {
  2183. X        werase(l_win);
  2184. X        wrefresh(l_win);
  2185. X    }
  2186. X    delwin(l_win);
  2187. X    return(ret_code);
  2188. X}
  2189. X
  2190. X/*
  2191. X * Display the current settings.  Formats the entire string at one
  2192. X * time, in case you've got a magic cookie terminal.
  2193. X */
  2194. X
  2195. Xstatic void
  2196. Xdisp_settings(win)
  2197. XWINDOW *win;
  2198. X{
  2199. X    extern int xmc;
  2200. X    char buf[40];
  2201. X
  2202. X    sprintf(buf, "Current Settings: %5d,%c,%d,%d", dir->baud[dir->d_cur],
  2203. X     dir->parity[dir->d_cur], dir->dbits[dir->d_cur],
  2204. X     dir->sbits[dir->d_cur]);
  2205. X
  2206. X    if (xmc > 0) {
  2207. X        touchwin(win);
  2208. X        clear_line(win, 4, 8, 1);
  2209. X        wrefresh(win);
  2210. X    }
  2211. X    mvwattrstr(win, 4, 8, A_BOLD, buf);
  2212. X    return;
  2213. X}
  2214. SHAR_EOF
  2215. if test 4809 -ne "`wc -c < 'ls_menu.c'`"
  2216. then
  2217.     echo shar: "error transmitting 'ls_menu.c'" '(should have been 4809 characters)'
  2218. fi
  2219. fi
  2220. exit 0
  2221. #    End of shell archive
  2222.  
  2223. -- 
  2224. Please send comp.sources.unix-related mail to rsalz@uunet.uu.net.
  2225.